﻿using MediatR;
using WMS.API.Application.Command.BasicManagement;
using WMS.Domain.Entities.BasicManagement;
using WMS.ErrorCode;
using WMS.Interfactructure.Interfaces;

namespace WMS.API.Application.CommandHandlers.BasicManagement
{
    public class WarehouseModelCommandHandler : IRequestHandler<WarehouseModelCommand, APIResult<IQueryable<WarehouseModel>>>
    {
        IBaseRepository<WarehouseModel> _warehouseModelBaseRepository;

        public WarehouseModelCommandHandler(IBaseRepository<WarehouseModel> warehouseModelBaseRepository)
        {
            _warehouseModelBaseRepository = warehouseModelBaseRepository;
        }
        /// <summary>
        /// 仓库下拉命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<APIResult<IQueryable<WarehouseModel>>> Handle(WarehouseModelCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var model = _warehouseModelBaseRepository.GetAll();
                return Task.FromResult(new APIResult<IQueryable<WarehouseModel>>("仓库下拉框查询成功")
                {
                    Code = ResultCode.Success,
                    Data = model
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
